
$(document).ready(function () {
    var transfereesubmit_form = $(".transfereesubmit");

    transfereesubmit_form.on('focus', '.l_b input:not(".read_only")', function () {
        $(this).addClass('u-ipt-active');
        $(this).removeClass('error');
        $(this).next('.error').hide();
    })

    transfereesubmit_form.on('blur', '.l_b input:not(".read_only")', function () {
        $(this).removeClass('u-ipt-active');
        if ($(this).parents('.l_b').find('label.error').is(":visible")) {
            $(this).addClass('error');
            $(this).parents('.l_b').find('.prompt').hide();
        } else {
            $(this).removeClass('error');
            $(this).removeClass('u-ipt-active');
            $(this).parents('.l_b').find('.prompt').show();
        }
    })

    var record;
    // 范围要求在大于等于0，小于等于9999999999.99之间
    transfereesubmit_form.on('keyup', '.repayment', function () {
        var myThis = $(this);
        var val = myThis.val();
        var decimalReg = /^\d{0,999}\.{0,1}(\d{1,2})?$/;
        if (val != '' && decimalReg.test(val)) {
            record = val;
        } else {
            if (val != '') {
                myThis.val(record);
            }
        }
        myThis.blur(function () {
            record = '';
        });
    });
    
    $("#success").click(function(event) {

          var b = true;
       $('.repayment').each(function () {
            var that = $(this);
            var pay = parseFloat(that.val());
            var repaid = parseFloat(that.parents('tr').find('.repaid').val());
            var repayments = parseFloat(that.parents('tr').find('.repayments').val());
        
            if(that.val()==''){
                that.removeClass('valid');
                that.addClass('error');
                that.parent('.l_b').find('label').remove();
                var l = '<label id="'+that.prop("name")+'-error" class="error" for="'+that.prop("name")+'">请填写还款金额</label>'
                that.parent('.l_b ').append(l);
                b = false;

            }else if(that.val()!==''){
               if(parseFloat(pay+repaid)>repayments){
                    that.removeClass('valid');
                    that.addClass('error');
                    that.parent('.l_b').find('label').remove();
                    var l = '<label id="'+that.prop("name")+'-error" class="error" for="'+that.prop("name")+'">还款金额错误</label>'
                    that.parent('.l_b ').append(l);
                     b = false

                } 
                
            }

    });

     if(b)
        {
          oktipsoption = {
                     type: 1,
                     url: $('.formsub').attr('url'),
                     msg: '提交成功'
                 };
         ajaxform.init(oktipsoption, '.formsub');
         ajaxform.submit();

        }
       });
})